package com.bloveoacom.weichi.activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bloveoacom.base.BaseActivity;
import com.bloveoacom.base.UserInfoBean;
import com.bloveoacom.http.HttpMethods;
import com.bloveoacom.http.RxHelper;
import com.bloveoacom.observer.BaseSubscriber2;
import com.bloveoacom.util.Constant;
import com.bloveoacom.util.DisplayUtil;
import com.bloveoacom.util.EncodingHandler;
import com.bloveoacom.util.GlideUtil;
import com.bloveoacom.util.GsonUtil;
import com.bloveoacom.util.NumberUtil;
import com.bloveoacom.util.StringUtils;
import com.bloveoacom.weichi.R;
import com.bloveoacom.weichi.bean.ActivitysBean;
import com.bloveoacom.weight.LlkjToolBar;
import com.google.zxing.WriterException;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.bloveoacom.util.PicCameraLocalUtil.recycle;

/**
 * author: yjl
 * e-mail: 1271901673@qq.com
 * time  : 2018/9/21
 * desc  :
 */
public class OrderDetailActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    LlkjToolBar mToolbar;
    @BindView(R.id.iv_pic)
    ImageView ivPic;
    @BindView(R.id.tv_activity_title)
    TextView tvActivityTitle;
    @BindView(R.id.tv_activity_time)
    TextView tvActivityTime;
    @BindView(R.id.iv_code)
    ImageView ivCode;
    @BindView(R.id.tv_code)
    TextView tvCode;

    private int height;

    @Override
    public int getLayoutResId() {
        return R.layout.activity_orderdetail;
    }

    @Override
    protected View getViewSetTB() {
        return mToolbar;
    }
    private Bitmap qrCode;
    @Override
    public void initView() {
        mToolbar.setToolBar("",
                true, "", R.drawable.ic_back, false, "", LlkjToolBar.isNull);
        height = DisplayUtil.getDensityWdith(mContext) - DisplayUtil.dip2px(mContext, 80) * 2;
        try {
            qrCode = EncodingHandler.createQRCode("123455", height);
            ivCode.setImageBitmap(qrCode);
        } catch (WriterException e) {
            e.printStackTrace();
        }

    }
    int orderId;
    @Override
    public void initData() {
        BaseSubscriber2<ActivitysBean> baseSubscriber2 = HttpMethods.getInstance().getHttpService().getTicketRecordDetail(UserInfoBean.getInstance().getToken(), orderId).compose(RxHelper.getData()).subscribeWith(new BaseSubscriber2<ActivitysBean>(this) {
            @Override
            public void onNext(ActivitysBean o) {
                super.onNext(o);
                tvActivityTime.setText(o.activityTime+"-"+o.activityEndtime);
                tvActivityTitle.setText(o.title);
                GlideUtil.loadRoundmage(ivPic, StringUtils.getFullUrl(o.img,0));
                tvCode.setText(o.orderNo);
                GlideUtil.loadImage(ivCode, StringUtils.getFullUrl(o.qrcode,0));
            }
        });
        addDispose(baseSubscriber2);
    }

    @Override
    public void getBundleExtras(Bundle extras) {
        orderId = NumberUtil.getIntByStr(extras.getString(Constant.DATA0));
    }

    @Override
    public void initListener() {

    }

    @Override
    public void onDestroy() {
        recycle(qrCode);
        super.onDestroy();
    }
}
